var WxCacheModel = $.extend(TradeModel, {
    selRow: null,
    editor:{
        title: '缓存',
        winid:'WxCache_EditForm',
        formid:'WxCache_EditForm_fm',
        width:720,
        height:300
    },
    postAction: 'add',
    url: '/contest18/mgr/wxCache',
    title: '缓存',
    idField: "cacheMemo",
    titleField: "cacheMemo",
    toolbar: 'WxCache_Toolbar',
    datagrid: 'WxCache_Grid'
});

WxCacheModel.reload =function() {
    ReloadList_WxCache();
    $('#WxCache_EditForm').dialog('close');
}


function Del_WxCache() {
    var _checkedItems = $('#WxCache_Grid').datagrid('getChecked');
    var _delcount=0;
    var _names = '';
    if(_checkedItems.length<1) {
        $.messager.alert('提示', '请选择需要删除的数据!' );
        return;
    }
    $.each(_checkedItems, function(index, item){
        _names +='<br/>'+ item[WxCacheModel.titleField] ;
    });
    var url = WxCacheModel.url+'/del' ;
    $.messager.confirm('确定要删除如下信息?', '' + _names , function (r) {
        if (r) {
            var postdata={
                "reqBody": {} ,
                "reqHead": {
                    "sysCode": "contest18_test"
                }
            }
            $.each(_checkedItems, function(index, item){
                postdata.reqBody=item;
                Onluy.ajax.postData(url,postdata,  function(result){
                    if (result.rspCode ==0) {
                        _delcount++;
                    }
                },function(error){  } );
            });
            $.messager.alert('提示', '成功删除'+_delcount+'条数据!' );
            ReloadList_WxCache();
        }
    });
}

function ShowEditForm_WxCache(type) {
    switch (type) {
        case  1:
            var checkedItems = $('#WxCache_Grid').datagrid('getChecked');
            if(checkedItems.length>1){
                $.messager.alert('提示', '只能选择一条记录修改!' );
                return;
            }
            WxCacheModel.selRow = checkedItems[0];
            WxCacheModel.postAction = 'update';
            break;

        case  0:
        default:
            WxCacheModel.selRow = {}
            WxCacheModel.postAction = 'add';
            break;
    }

    $('#WxCache_EditForm_fm').form('clear' );
    $('#WxCache_EditForm_fm').form('load', WxCacheModel.selRow);
    $('#WxCache_EditForm').dialog({
        resizable: false,
        maximizable: false
    })
        .dialog('open')
        .dialog('setTitle', (WxCacheModel.postAction == 'add') ? '新增' + WxCacheModel.title : '修改' + WxCacheModel.selRow[WxCacheModel.titleField]);
}

function save_WxCache() {
    WxCacheModel.submit();
}


function WxCacheSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#WxCache_Grid').datagrid('reload');
    }
}

function ReloadList_WxCache() {
    $('#WxCache_Grid').datagrid('reload');
}



$(function () {
    $('#WxCache_Grid').datagrid({
        pageSize: 10,
        fit: true,
        checkOnSelect: true,
        selectOnCheck: true,
        singleSelect: false,
        checkbox: true,
        fitColumns: true,
        pagination: true,
        method: 'post',
        url: WxCacheModel.url+'/list',
        loader:WxCacheModel.Loader,
        toolbar: '#WxCache_Toolbar',
        columns: [
            [
                { field: 'ck',  checkbox: true },
                { field: 'cacheKey', title: 'key', width:100, align: 'left',sortable:true },
                { field: 'cacheName', title: '名称', width:200, align: 'left',sortable:true },
                { field: 'cacheMemo', title: '备注', width:300, align: 'left',sortable:true },
                { field: 'cacheDuration', title: '时长', width:50, align: 'left',sortable:true }
            ]
        ],


        onLoadError: function (res) {
            WxCacheModel.ShowException(res);
        },
        onLoadSuccess: function (data) {
            if(data.success){ }
            else if(data.msg){
                $.messager.alert('加载错误', data.msg );
            }
        },
        onBeforeLoad: function (param) {
            $('#WxCache_Grid').datagrid('clearSelections');
            param['catchKey'] = Math.random();
            param['name'] = $('#WxCache_ss').searchbox('getName');
            param['value'] = $('#WxCache_ss').searchbox('getValue');
        }
    });
    //设置分页控件
    var p = $('#WxCache_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 10, //每页显示的记录条数，默认为10
        pageList: [10,20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



